#include <iostream>
using namespace std;

int partion(int *a, int lo, int hi)
{
        int i = lo, j = lo, &key = a[hi - 1];
        for(int j = lo; j < hi - 1; j++){
                if(a[j] < key){
                        swap(a[j], a[i++]);
                }
        }
        swap(a[i], key);
        return i;
}

void quick_sort(int *a, int lo, int hi)
{
        if(hi - lo > 1){
                int p = partion(a, lo, hi);
                quick_sort(a, lo, p);
                quick_sort(a, p, hi);
        }
}

int num[10000000];
int seq[10000000];
int exst[10000000];
int main()
{
        ios::sync_with_stdio(false);
        cin.tie(nullptr);

	int n = 0, m = 0;
	cin >> n >> m;
	int maxn = -1;
	for (int i = 0; i < n; i++) {
		cin >> num[i];
		maxn = max(maxn, num[i]);
	}
	quick_sort(&num[0], 0, n);

	for (int i = 0; i < n; i++) {
		seq[num[i]] = i + 1;
	}

	for (int i = 1; i <= maxn; i++) {
		if (seq[i] == 0) {
			seq[i] = seq[i - 1];
		}else{
                        exst[i] = 1;
                }
	}

        for(int i = 0, a, b; i < m; i++){
                cin >> a >> b;

                if(b <= maxn){
                        cout << seq[b] - seq[a] + (exst[a] ? 1 : 0) << '\n';
                }else if( a <= maxn){
                        cout << seq[maxn] - seq[a] +  (exst[a] ? 1 : 0) << '\n';
                }else{
                        cout << 0 << '\n';
                }
        }
        return 0;
}